package com.onlyoffice.demo.findproblem.controller;

import com.onlyoffice.demo.findproblem.domain.ClickCheckRequest;
import com.onlyoffice.demo.findproblem.domain.ClickCheckResponse;
import com.onlyoffice.demo.findproblem.domain.GameLevel;
import com.onlyoffice.demo.findproblem.service.GameService;
import com.onlyoffice.demo.onlyoffice.domain.R;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/game")
@RequiredArgsConstructor
public class GameController {

    private final GameService gameService;

    /**
     * 获取关卡列表
     *
     * @return 关卡列表
     */
    @GetMapping("/levels")
    public R<List<GameLevel>> getLevels() {
        return R.ok(gameService.getAllLevels());
    }

    /**
     * 获取关卡详情（不含错误点坐标）
     *
     * @param id 关卡Id
     * @return 关卡详情（不含错误点坐标）
     */
    @GetMapping("/level/{id}")
    public R<GameLevel> getLevel(@PathVariable Long id) {
        return R.ok(gameService.getLevelForPlay(id));
    }

    /**
     * 检查点击是否命中错误点
     *
     * @param request 请求参数
     * @return 是否命中错误点
     */
    @PostMapping("/check-click")
    public R<ClickCheckResponse> checkClick(@RequestBody ClickCheckRequest request) {
        return R.ok(gameService.checkClick(request));
    }
}